package com.iot.service;

import com.iot.mapper.DRefMapper;
import com.iot.mapper.DTdeviceMapper;
import com.iot.pojo.MRef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RefServiceImpl implements RefService {

    @Autowired
    private DRefMapper dRefMapper;
    @Autowired
    private DTdeviceMapper dTdeviceMapper;

    @Override
    public List<MRef> initProvince() {
        List<MRef> cityList = dRefMapper.getProvince();
        return cityList;
    }

    @Override
    public List<MRef> initProvinceBySelfId(int provinceId) {
        List<MRef> cityList = dRefMapper.getProvinceById(provinceId);
        return cityList;
    }

    @Override
    public List<MRef> initCityById(int provinceId) {
        List<MRef> cityList = dRefMapper.getCity(provinceId);
        return cityList;
    }

    @Override
    public List<MRef> initCityBySelfId(int provinceId, int city) {
        List<MRef> cityList = dRefMapper.getCityById(provinceId, city);
        return cityList;
    }

    @Override
    public List<MRef> initAreaById(int cityId) {
        List<MRef> areaList = dRefMapper.getArea(cityId);
        return areaList;
    }

    @Override
    public List<MRef> initRegionById(int areaId, int appId) {
        List<MRef> regionList = dRefMapper.getRegion(areaId, appId);
        return regionList;
    }

    @Override
    public List<MRef> initSiteById(int regionId, int appId) {
        List<MRef> regionList = dRefMapper.getSite(regionId, appId);
        return regionList;
    }

    @Override
    public List<MRef> initLineById(int siteId, int appId) {
        List<MRef> list = dRefMapper.getLine(siteId, appId);
        return list;
    }

    @Override
    public List<MRef> initDeviceStatus() {
        List<MRef> list = dRefMapper.getDeviceStatus();
        return list;
    }

    @Override
    public List<MRef> initDeviceType() {
        List<MRef> list = dRefMapper.getDeviceType();
        return list;
    }

    @Override
    public List<MRef> initDevice(HashMap<String, Object> map) {
        List<MRef> list=new ArrayList<>();
        List<Map<String, Object>> devList = dTdeviceMapper.fetchByPage(map);
        if (devList.size() > 0) {
            for (Map<String,Object> item:devList)
            {
                list.add(new MRef(item.get("DEVICE_ID").toString(),item.get("SNAME").toString()));
            }

        }
        return list;
    }

    @Override
    public List<MRef> initSensor(int typeId) {
        List<MRef> list = dRefMapper.getSensor(typeId);
        return list;
    }

    @Override
    public List<MRef> initWarnType(int typeId) {
        List<MRef> list = dRefMapper.getWarnType(typeId);
        return list;
    }

}
